package com.cyzy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyzy.dto.CropDto;
import com.cyzy.dto.FieldDto;
import com.cyzy.dto.PlotOrdersPayDto;
import com.cyzy.dto.Result;
import com.cyzy.pojo.*;
import com.cyzy.service.*;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;


@RestController
@RequestMapping("/secondKill")
public class LandSecondController {
    @Autowired
    private LandSecondService landSecondService;
    @GetMapping("/selectAll")
    public Result selectAll(TbSecondkill secondkill) {
        List<TbSecondkill> list = landSecondService.selectAll(secondkill);
        return Result.ok().data("list",list);
    }
    //查询单个秒杀
    @GetMapping("/selectById")
    public Result selectAll(@RequestParam("landId") Long skId) {
        TbSecondkill tbSecondkill = landSecondService.selectBySkId(skId);
        return Result.ok().data("tbSecondkill",tbSecondkill);
    }
    //查询具体农场信息
    @GetMapping("/selectLandById")
    public Result selectLandById(@RequestParam("landId") Long landId) {
        TbLand tbLand = landSecondService.selectLandById(landId);
        return Result.ok().data("tbLand",tbLand);
    }
    //生成订单
    @PostMapping("/generateOrder")
    public Result generateOrder(TbLandorder tbLandorder) {
        int affect = landSecondService.generateOrder(tbLandorder);
        if (affect>0){
            return Result.ok().message("生成订单成功");
        }else{
            return Result.ok().message("生成订单失败");
        }

    }
    //查询订单
    @GetMapping("/selectOrderById")
    public Result selectOrderById(Long orderId) {
        TbLandorder tbLandorder = landSecondService.selectOrderById(orderId);
        return Result.ok().data("tbLandorder",tbLandorder);
    }

}
